package com.haiheng.library_base.db.converters
import androidx.room.TypeConverter
import com.google.gson.Gson
import com.haiheng.library_base.db.BookInfoBean
import com.haiheng.library_base.db.BookInfoSub

/**
 *
 * @Des:
 * @Author: hwz
 * @Date:2023/7/17 0017
 * @Version: 1.0
 */


class BookInfoSubConverter {
    private val gson = Gson()

    @TypeConverter
    fun fromBookInfoSub(bookInfoSub: BookInfoSub?): String {
        return bookInfoSub?.let { gson.toJson(it) } ?: ""
    }

    @TypeConverter
    fun toBookInfoSub(bookInfoSubString: String): BookInfoSub {
        return if (bookInfoSubString.isNotEmpty()) {
            gson.fromJson(bookInfoSubString, BookInfoSub::class.java)
        } else {
            BookInfoSub() // Return a default BookInfoSub object if the input string is empty
        }
    }
}

